package me.landery.modules.sinco.domain;

import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;
import me.landery.base.BaseEntity;
import me.landery.modules.system.domain.User;

import javax.persistence.*;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.util.Date;
import java.util.Objects;

/**
 * @Author cc.w
 * @Date 2022/6/7 22:13
 * @Version 1.0
 */
@Entity
@Getter
@Setter
@Table(name="sinco_recharge")
public class Recharge extends BaseEntity implements Serializable {
    @Id
    @Column(name = "rid")
    @NotNull(groups = BaseEntity.Update.class)
    @ApiModelProperty(value = "充值记录ID", hidden = true)
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id; //订单id

    @OneToOne
    @JoinColumn(name = "uid")
    @ApiModelProperty(value = "充值的用户")
    private User user; //支付的user

    @ApiModelProperty(value = "用户充值金额")
    private Double balance; //支付金额


    @Column(name="recharge_state")
    @ApiModelProperty(value = "用户充值状态")
    private Integer rechargeState; //用户充值状态

    /**
     *  if(d.rechargeState==1){
     *                         return "无效交易";
     *                     }else if(d.rechargeState==2){
     *                         return "等待确认";
     *                     }else if(d.rechargeState==3){
     *                         return "充值成功";
     *                     }else {
     *                         return "未知状态";
     *                     }
     */
    @Column(name="recharge_type")
    @ApiModelProperty(value = "用户充值方式")
    private String rechargeType; //用户充值方式



    @Column(name="detail")
    @ApiModelProperty(value = "用户充值详情")
    private String detail; //用户充值详情

    @Column(name = "time")
    @ApiModelProperty(value = "充值记录产生时间", hidden = true)
    private Date time; //支付时间


    @Column(name="trade_no")
    @ApiModelProperty(value = "用户充值交易号")
    private String tradeNo; //支付宝交易号

    @NotBlank
    @Column(name="out_trade_no")
    @ApiModelProperty(value = "商户订单号")
    private String outTradeNo; //商户订单号


    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        Recharge recharge = (Recharge) o;
        return Objects.equals(id, recharge.id);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id);
    }
}
